package Jan;

import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Kunde {

	public int kundennummer;
	public String nachname;
	public String vorname;
	public Date geburtsdatum;
	public String geschlecht;
	public String l_strasse;
	public String l_hausnummer;
	public String l_plz;
	public String l_ort;
	public String r_strasse;
	public String r_hausnummer;
	public String r_plz;
	public String r_ort;
	public String telefonnummer;
	public String email;
	public String blz;
	public String kontonummer;
	public String iban;
	public String bic;
	public int filiale;
	

	
	public Kunde(int kundennummer, String nachname, String vorname,
			Date geburtsdatum, String geschlecht, String l_strasse,
			String l_hausnummer, String l_plz, String l_ort, String r_strasse,
			String r_hausnummer, String r_plz, String r_ort,
			String telefonnummer, String email, String blz, String kontonummer,
			String iban, String bic, int filiale) {

		this.kundennummer = kundennummer;
		this.nachname = nachname;
		this.vorname = vorname;
		this.geburtsdatum = geburtsdatum;
		this.geschlecht = geschlecht;
		this.l_strasse = l_strasse;
		this.l_hausnummer = l_hausnummer;
		this.l_plz = l_plz;
		this.l_ort = l_ort;
		this.r_strasse = r_strasse;
		this.r_hausnummer = r_hausnummer;
		this.r_plz = r_plz;
		this.r_ort = r_ort;
		this.telefonnummer = telefonnummer;
		this.email = email;
		this.blz = blz;
		this.kontonummer = kontonummer;
		this.iban = iban;
		this.bic = bic;
		this.filiale = filiale;
	}


	public int getKundennummer() {
		return kundennummer;
	}

	


	public void setKundennummer(int kundennummer) {
		this.kundennummer = kundennummer;
	}





	public String getNachname() {
		return nachname;
	}





	public void setNachname(String nachname) {
		this.nachname = nachname;
	}





	public String getVorname() {
		return vorname;
	}





	public void setVorname(String vorname) {
		this.vorname = vorname;
	}





	public Date getGeburtsdatum() {
		return geburtsdatum;
	}





	public void setGeburtsdatum(Date geburtsdatum) {
		this.geburtsdatum = geburtsdatum;
	}





	public String getGeschlecht() {
		return geschlecht;
	}





	public void setGeschlecht(String geschlecht) {
		this.geschlecht = geschlecht;
	}





	public String getL_strasse() {
		return l_strasse;
	}





	public void setL_strasse(String l_strasse) {
		this.l_strasse = l_strasse;
	}





	public String getL_hausnummer() {
		return l_hausnummer;
	}





	public void setL_hausnummer(String l_hausnummer) {
		this.l_hausnummer = l_hausnummer;
	}





	public String getL_plz() {
		return l_plz;
	}





	public void setL_plz(String l_plz) {
		this.l_plz = l_plz;
	}





	public String getL_ort() {
		return l_ort;
	}





	public void setL_ort(String l_ort) {
		this.l_ort = l_ort;
	}





	public String getR_strasse() {
		return r_strasse;
	}





	public void setR_strasse(String r_strasse) {
		this.r_strasse = r_strasse;
	}





	public String getR_hausnummer() {
		return r_hausnummer;
	}





	public void setR_hausnummer(String r_hausnummer) {
		this.r_hausnummer = r_hausnummer;
	}





	public String getR_plz() {
		return r_plz;
	}





	public void setR_plz(String r_plz) {
		this.r_plz = r_plz;
	}





	public String getR_ort() {
		return r_ort;
	}





	public void setR_ort(String r_ort) {
		this.r_ort = r_ort;
	}





	public String getTelefonnummer() {
		return telefonnummer;
	}





	public void setTelefonnummer(String telefonnummer) {
		this.telefonnummer = telefonnummer;
	}





	public String getEmail() {
		return email;
	}





	public void setEmail(String email) {
		this.email = email;
	}





	public String getBlz() {
		return blz;
	}





	public void setBlz(String blz) {
		this.blz = blz;
	}





	public String getKontonummer() {
		return kontonummer;
	}





	public void setKontonummer(String kontonummer) {
		this.kontonummer = kontonummer;
	}





	public String getIban() {
		return iban;
	}





	public void setIban(String iban) {
		this.iban = iban;
	}





	public String getBic() {
		return bic;
	}





	public void setBic(String bic) {
		this.bic = bic;
	}





	public int getFiliale() {
		return filiale;
	}





	public void setFiliale(int filiale) {
		this.filiale = filiale;
	}



	public static Kunde transformOfNewCustomer(Customer customerFromFiliale1, Connection con_o) {

		Kunde kunde = new Kunde(
				generateNewCustomerIDOnlineShop(con_o),
				customerFromFiliale1.getCustomer_lastname(),
				customerFromFiliale1.getCustomer_firstname(),
				customerFromFiliale1.getCustomer_birthday(),
				"",
				customerFromFiliale1.getCustomer_delivery_street(),
				customerFromFiliale1.getCustomer_deliv_street_number(),
				customerFromFiliale1.getCustomer_delivery_postal_code(),
				customerFromFiliale1.getCustomer_delivery_place(),
				customerFromFiliale1.getCustomer_billing_street(), 
				customerFromFiliale1.getCustomer_bill_street_number(),
				customerFromFiliale1.getCustomer_billing_postal_code(), 
				customerFromFiliale1.getCustomer_billing_place(),
				customerFromFiliale1.getCustomer_phone_number(), 
				customerFromFiliale1.getCustomer_email(), 
				"",
				"",
				"",
				"",
				1);
		return kunde;
	}
	

	private static int generateNewCustomerIDOnlineShop(Connection con_o) {
		int newCustomerID = 0;
		ResultSet rs1 = null;
		Statement stmt1 = null;
		try {
			stmt1 = con_o.createStatement();
			rs1 = stmt1.executeQuery("SELECT MAX(KUNDENNUMMER) AS KUNDENNUMMER FROM KUNDE"); 		
				while (rs1.next()) {
					newCustomerID = rs1.getInt("KUNDENNUMMER") + 1;
				}
				stmt1.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return newCustomerID;
	}





}
